<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <!-- <img src="../assets/avatar.04360fb6.jpg" /> -->
        <span>超算中心资源管理</span>
      </div>
      <el-button type="info" @click="logout">登出</el-button>
    </el-header>
    <el-container>
      <!-- 页面主题区域 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="isCollapse=!isCollapse"><i :class="isCollapse?'el-icon-s-unfold':'el-icon-s-fold'"></i></div>
        <!-- <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF"
          :unique-opened='true' :collapse="isCollapse" :collapse-transition='false'
          :router="true" :default-active="activePath">
          <el-menu-item :index="item.path + ''" v-for="item in menulist" :key="item.id" @click="savaNavState(item.path)">
            <template>
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
          </el-menu-item>
        </el-menu> -->
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409eff" :default-openeds="defaultOpeneds"
				         :unique-opened="false" :collapse="isCollapse" :collapse-transition="false"
				         :router="true" :default-active="activePath">
					<!-- 一级菜单 -->
					<el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
						<template slot="title">
							<i :class="iconsObj[item.id]"></i>
							<span>{{ item.authName }}</span>
						</template>
						<!-- 二级菜单 -->
						<el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState('/'+subItem.path)">
							<template slot="title">
								<i class="el-icon-menu"></i>
								<span>{{ subItem.authName }}</span>
							</template>
						</el-menu-item>
					</el-submenu>
				</el-menu>
      </el-aside>
      <!-- 右侧内容主题 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [
        { authName: 'HPC', path: 'hpc', id: '10', children: [
          {authName: '资源总表', path: 'hpctotalResource', id: '101'},
          {authName: '资源使用总表', path: 'usageResource', id: '102'},
          {authName: '合同总表', path: 'totalContract', id: '103'}
          ]
        },
        { authName: 'IDC', path: 'idc', id: '20', children: [
          // {authName: '资源总量', path: 'totalResource', id: '201'},
          // {authName: '剩余可用资源数量', path: 'remainResource', id: '202'},
          {authName: '物理机资源总表', path: 'totalHostResource', id: '203'},
          {authName: '物理机资源使用情况', path: 'usageHostResource', id: '204'},
          ]
        }
      ],
      iconsObj: {
        '10': 'iconfont icon-danju',
        '20': 'iconfont icon-baobiao'
      },
      isCollapse: false,
      //被激活的地址
      activePath: '',
      defaultOpeneds: []
    };
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },

    toggleCollaps() {
      this.isCollapse = !this.isCollapse
    },
    saveNavState(activePath) {  
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 25px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
  img {
    max-height: 60px;
    border-radius: 50%;
  }
}

.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin-right: 20px;
	font-size: 20px;
}

.toggle-button {
  background-color: #4A5064;
  font-size: 20px;
  line-height: 25px;
  color: #fff;
  text-align: center;
  letter-spacing: -0.1em;
  cursor: pointer;
}
</style>